// AntiDiagonal.java

/*
 * 本类实现反对角方式的方阵遍历：
 */
public class AntiDiagonal extends SquareTraversal{

    public AntiDiagonal(int size) {
        // 在这里添加代码：
        initiate(size);
    }

    @Override public SquarePoint getInitPoint() {
        // 在这里添加代码：
        //左上角起点
        return new SquarePoint(0,0);
    }

    @Override public SquarePoint getNext() {
        // 在这里添加代码：
        SquarePoint currentPoint = currentPath.get(currentPath.size() - 1);

        int currRow = currentPoint.getRow();
        int currCol = currentPoint.getCol();
        int nextRow = currRow;
        int nextCol = currCol;

        if(currRow == size - 1 && currCol == size - 1){
            //右下角终点
            return null;
        }else if(currRow == 0 && currCol == size - 1){
            //右上角特殊处理
            nextCol = 1;
            nextRow = size -1;
        }else if (currRow == 0 ) {
            //第一行
            nextCol = 0;
            nextRow = currCol+1;
        }else if (currCol == size - 1) {
            //最后一列
            nextRow=size-1;
            nextCol = currRow + 1;
        }else {
            //一般情况
            nextCol=currCol+1;
            nextRow=currRow-1;
        }


        return new SquarePoint(nextRow, nextCol);
    }

    private int getStartingRow(int sum) {
        // 在这里添加代码：
        //?
        return  0;
    }
}